<template>
	<view class="content">
		<view class="example">
			<overhaul-step :bidding="isBidding" :active="active" />
			<view class="buttn">
				<button type="primary" @click="submitData">提交</button>
			</view>
		</view>
		<view class="criter_bt">
			<view class="line"></view>
			<text>基本信息</text>
		</view>
		<view class="dec_main">
			<view class="dec_li dush_li">
				<view class="dec_le">
					<label>当前用户：</label>
				</view>
				<view class="dec_ri">
					<text>{{ userName }}</text>
				</view>
			</view>
			<view class="dec_li dush_li">
				<view class="dec_le">
					<label>所属部门：</label>
				</view>
				<view class="dec_ri">
					<text>{{ deptName }}</text>
				</view>
			</view>
			<view class="dec_li">
				<view class="dec_le">
					<label>申报时间：</label>
				</view>
				<view class="dec_ri">
					<text>{{ now }}</text>
				</view>
			</view>
		</view>
		<view class="criter_bt">
			<view class="line"></view>
			<text>检修信息</text>
		</view>
		<!-- 新增需求 -->
		<view class="text-center">
			<view class="cu-item " :class="{
				'tab-date-on':index==tabChangeCur
			}" v-for="(item,index) in tabsChanges" :key="index" @tap="tabSelect" :data-id="index">
				{{item}}
			</view>
		</view>


		<view class="search">
			<uni-search-bar v-model="searchKey1" style="flex: 1;" radius="5" placeholder="设备名称/设备位号" clearButton="auto"
				cancelButton="none" @confirm="search1" @clear="clear1" v-if="tabChangeCur==0" />
			<u-button style="width: 94%;height: 70rpx;background-color: #f7f7f7;margin:16rpx; " :plain="true"
				v-if="tabChangeCur==1" @click="fetchPartition()">位置名称/位置编码</u-button>
		</view>


		<!-- 获取设备位置信息 -->
		<div class="deviceInfo" v-if="deviceInfo.device_id &&  tabChangeCur==0">
			<div class="deviceInfo_left">
				<div class="flex align-items label">
					<div class="deviceInfo_label">设备名称：</div>
					<div class="deviceInfo_val">{{deviceInfo.device_name}}</div>
				</div>
				<div class="flex align-items label">
					<div class="deviceInfo_label">设备编码：</div>
					<div class="deviceInfo_val">{{deviceInfo.device_code}}</div>
				</div>
				<div class="flex align-items label">
					<div class="deviceInfo_label">设备分类：</div>
					<div class="deviceInfo_val">{{deviceInfo.device_type_name}}</div>
				</div>
				<div class="flex align-items label">
					<div class="deviceInfo_label">使用部门：</div>
					<div class="deviceInfo_val">{{deviceInfo.use_dept_name}}</div>
				</div>
				<div class="flex align-items label">
					<div class="deviceInfo_label">检修装置：</div>
					<div class="deviceInfo_val">{{deviceInfo.pro_line_name}}</div>
				</div>
			</div>
			<uni-icons type="closeempty" size="20" color="#333" @click="removeDevice" />
		</div>
		<div class="deviceInfo" v-if="deptInfo.partition_id &&  tabChangeCur==1">
			<div class="deviceInfo_left">
				<div class="flex align-items label">
					<div class="deviceInfo_label">位置名称：</div>
					<div class="deviceInfo_val">{{deptInfo.partition_name}}</div>
				</div>
				<div class="flex align-items label">
					<div class="deviceInfo_label">位置编码：</div>
					<div class="deviceInfo_val">{{deptInfo.partition_code}}</div>
				</div>
				<div class="flex align-items label">
					<div class="deviceInfo_label">所属部门：</div>
					<div class="deviceInfo_val">{{deptInfo.dept_name}}</div>
				</div>
			
			</div>
			<uni-icons type="closeempty" size="20" color="#333" @click="removeDeviceTwo" />
		</div>

		<view class="dec_main">
			<view class="dec_li bottom-view">
				<view class="dec_le">
					<label>*检修类型：</label>
				</view>
				<picker @change="otypeChange" :value="otIndex" :range="oType">
					<view>{{ oType[otIndex] }}</view>
				</picker>
			</view>

			<view class="dec_li bottom-view">
				<view class="dec_le">
					<label>*单据类型：</label>
				</view>
				<picker @change="billChange" :value="billIndex" :range="billType">
					<view>{{ billType[billIndex] }}</view>
				</picker>
			</view>

			<view class="dec_li bottom-view">
				<view class="dec_le">
					<label>*施工类型：</label>
				</view>
				<picker @change="buildChange" :value="buildIndex" :range="build" range-key="dic_value">
					<view>{{ build[buildIndex].dic_value }}</view>
				</picker>
			</view>

			<view v-if="showBuild">
				<view class="dec_li">
					<view class="dec_le dec_flex">
						<label>*施工单位：</label>
					</view>
					<view class="dec_ri">
						<uni-easyinput class="inppu" trim="all" v-model="buildUnit" placeholder="请输入施工单位"
							maxlength="60"></uni-easyinput>
					</view>
				</view>
				<view class="dec_li">
					<view class="dec_le dec_flex">
						<label>*单位负责人：</label>
					</view>
					<view class="dec_ri">
						<uni-easyinput class="inppu" trim="all" v-model="buildPerson" placeholder="请输入施工单位负责人"
							maxlength="50"></uni-easyinput>
					</view>
				</view>
			</view>

		<!-- 	<view class="dec_li bottom-view" v-if="tabChangeCur ==0">
				<view class="dec_le">
					<label>*检修装置：</label>
				</view>
				<picker @change="eqChange" :value="eqIndex" :range="eqs" range-key="dic_value">
					<view>{{ eqs[eqIndex].dic_value }}</view>
				</picker>
			</view> -->

			<!-- <view class="dec_li">
				<view class="dec_le dec_flex">
					<label>*检修设备：</label>
				</view>
				<view class="dec_ri">
					<uni-easyinput class="inppu" trim="all" v-model="deviceName" placeholder="请输入检修设备名称"
						maxlength="50"></uni-easyinput>
				</view>
			</view>
			<view class="dec_li">
				<view class="dec_le dec_flex">
					<label>*设备位号：</label>
				</view>
				<view class="dec_ri">
					<uni-easyinput type="textarea" autoHeight class="inppu" trim="all" v-model="deviceCode"
						placeholder="请输入检修设备位号" maxlength="200"></uni-easyinput>
				</view>
			</view> -->
			<view class="dec_li">
				<view class="dec_le dec_flex">
					<label>工时：</label>
				</view>
				<view class="dec_ri">
					<uni-easyinput class="inppu" trim="all" v-model="workHours" type="number" placeholder="请输入工时(小时)"
						maxlength="20"></uni-easyinput>
				</view>
			</view>

			<view class="dec_li">
				<view class="dec_le">
					<label>拍照取证：</label>
				</view>
				<view class="dec_ri">
					<uni-file-picker limit="3" :sizeType="sizeType" @select="picSelect"
						@delete="picDelete"></uni-file-picker>
					<!-- 		<view class="pic-view">
						<view class="uni-input">物资照片</view>
						<view style="width: 70%; display: flex;" >
							<view v-for="(jtem, j) in pics2" :key = "j" style="margin: 10rpx;">
								<image :src="fileUrl + jtem" class="detail_img" @click="previewImg(jtem)"></image>
							</view>
						</view>
					</view> -->
				</view>
			</view>
			<view class="dec_li">
				<view class="dec_le">
					<label>*检修内容：</label>
				</view>
				<view class="dec_ri">
					<uni-easyinput type="textarea" autoHeight v-model="content" maxlength="-1"
						placeholder="请描述设备问题的详细情况"></uni-easyinput>
				</view>
			</view>
		</view>

		<!-- 审核信息 -->
		<view v-if="type == 1">
			<view class="criter_bt" v-if="false">
				<view class="line"></view>
				<text>审核信息</text>
			</view>

			<view class="dec_li dush_li bottom-view" v-if="false">
				<view class="dec_le">
					<label>*审核结果：</label>
				</view>
				<view class="dec_ri">
					<radio-group name="result" @change="radioChange">
						<label>
							<radio style="z-index: 1" value="r1" color="#267DFF" checked="true" /><text
								style="margin-left: 10rpx">通过</text>
						</label>
						<label>
							<radio style="z-index: 1" value="r2" color="#267DFF" :disabled="type == 1" /><text
								style="margin-left: 10rpx">驳回</text>
						</label>
					</radio-group>
				</view>
			</view>

			<view class="dec_li dush_li bottom-view">
				<view class="dec_le">
					<label>*仪表班长：</label>
				</view>
				<view class="dec_ri">
					<text>{{ userName }}</text>
				</view>
			</view>

			<view class="dec_li dush_li bottom-view">
				<view class="dec_le">
					<label>*签字确认：</label>
				</view>
				<view class="sign-view">
					<image :src="'data:image/svg+xml;base64,' + signStr" @click="previewImage" v-if="signStr != ''">
					</image>
					<Signature ref="sig" v-model="signStr" class="signture"></Signature>
					<text @click="startSign()">+</text>
				</view>
			</view>

			<view class="dec_li dush_li bottom-view">
				<view class="dec_le">
					<label>*许可检修时间：</label>
				</view>
				<view class="dec_ri">
					<uni-datetime-picker type="datetime" class="m-picker" v-model="permissionDate" :border="false"
						:clearIcon="false" />
					<!-- <text>{{now}}</text> -->
				</view>
			</view>
		</view>

		<view class="dec_li dush_li bottom-view">
			<view class="dec_le">
				<label>*计划开始时间：</label>
			</view>
			<view class="dec_ri">
				<uni-datetime-picker type="datetime" class="m-picker" v-model="permissionDate" :border="false"
					:clearIcon="false" />
				<!-- <text>{{now}}</text> -->
			</view>
		</view>

		<view class="dec_li dush_li bottom-view">
			<view class="dec_le">
				<label>*计划结束时间：</label>
			</view>
			<view class="dec_ri">
				<uni-datetime-picker type="datetime" class="m-picker" v-model="permissionEndDate" :border="false"
					:clearIcon="false" />
				<!-- <text>{{now}}</text> -->
			</view>
		</view>

		<view class="dec_li dush_li bottom-view">
			<view class="dec_le">
				<label>*审核部门：</label>
			</view>
			<picker @change="auditDeptChange" :value="auditIndex" :range="auditDepts" range-key="dept_name">
				<view>{{ auditDepts[auditIndex].dept_name }}</view>
			</picker>
		</view>

		<view class="dec_li dush_li bottom-view">
			<view class="dec_le">
				<label>*使用部门：</label>
			</view>
			<picker @change="useDeptChange" :value="useIndex" :range="useDepts" range-key="dept_name">
				<view>{{ useDepts[useIndex].dept_name }}</view>
			</picker>
		</view>

		<!-- <view class="sw-item">
			<view class="sw-label">*开启竞价：</view>
			<switch style="transform:scale(0.8)" :checked="isBidding" @change="biddingChange" color="#267DFF"></switch>
		</view> -->

		<view class="choose-box" v-if="!isBidding & (type == 1)">
			<view style="color: #267dff; font-size: 32rpx">*指派给:</view>
			<picker @change="teamPickerChange" :value="teamIndex" :range="teams" range-key="team_name">
				<view>{{ teams[teamIndex].team_name }}</view>
			</picker>
		</view>

		<helang-compress ref="helangCompress"></helang-compress>




		<!-- 弹出效果 -->
		<uni-popup id="device_popup" ref="device_popup" type='bottom' :animation="true" :maskClick="true">
			<view class="popup-content">
				<view class="popup-title">设备查询结果</view>
				<view v-for="(item, index) in deviceList" :key="index" @click="onPopClickItem(index)">
					<view class="card-action" style="position: relative;">
						<view style="flex: 1;">
							<view class="card-content">
								<view class="card-desc">设备名称：</view>
								<view class="card-value">{{item.device_name}}</view>
							</view>
							<view class="card-content">
								<view class="card-desc">设备编码：</view>
								<view class="card-value">{{item.device_code}}</view>
							</view>
							<view class="card-content">
								<view class="card-desc">设备分类：</view>
								<view class="card-value">{{item.device_type_name}} </view>
							</view>
							<view class="card-content">
								<view class="card-desc">使用部门：</view>
								<view class="card-value">{{item.use_dept_name}}</view>
							</view>
						</view>
						<image v-if="item.device_id == device_id" class="check-tag" src="/static/img/icon_checked.png">
						</image>
					</view>
				</view>
				<view style="padding-bottom:120rpx;"></view>
				<view class="con_btn">
					<button @click="resetClick()" class="confirm-btn" type="default">关闭</button>
					<button @click="confirmClick()" class="confirm-btn" type="primary">确定</button>
				</view>
			</view>
		</uni-popup>
		<ba-tree-picker ref="partitionPicker" :multiple='false' :numFind='false' @select-change="selectPartitionChange"
			title="位置信息" :localdata="partitionList" valueKey="partition_id" textKey="partition_name" />
	</view>
</template>

<script>
	import OverhaulStep from '@/components/selfs/OverhaulStep.vue'
	import Signature from '@/components/sin-signature/sin-signature.vue'
	import {
		getFormatDateTime,
		isCompareTime
	} from '@/utils/date-util.js'
	import {
		svg2Png
	} from '@/utils/base64.js'
	import helangCompress from '@/components/helang-compress/helang-compressTwo'
	import {
		uploadBase64Img,
		getTeamList,
		getThirdLevelDepts,
		getEqList,
		saveOverhaulInfo,
		uploadImgUrl,
		getBuildType,
		getDeviceList,
		getBasePartitionList
	} from '@/api/maintenance/selfs.js'
	export default {
		components: {
			OverhaulStep,
			Signature,
			helangCompress,
		},
		data() {
			return {
				sizeType: ['compressed'],
				isBidding: false,
				active: 0,
				type: 0,
				userName: '',
				userId: '',
				deptName: '',
				deptId: '',
				now: '',
				deviceName: '',
				deviceCode: '',
				workHours: '',
				content: '',
				imgPaths: [],
				signStr: '',
				signPng: '',
				permissionDate: '',
				permissionEndDate: '',
				result: true,
				uploadImgUrl: uploadImgUrl,
				teamIndex: 0,
				teams: [{
					team_name: '请选择接收任务班组',
				}, ],
				auditDepts: [{
					dept_name: '请选择审核部门',
				}, ],
				auditIndex: 0,
				useDepts: [{
					dept_name: '请选择使用部门',
				}, ],
				useIndex: 0,
				eqs: [{
					dic_value: '请选择检修装置',
				}, ],
				eqIndex: 0,
				oType: ['计划维修', '故障事故维修'],
				otIndex: 0,
				billType: ['自主检修', '市场化检修', '互助检修'],
				billIndex: 0,
				showBuild: false,
				build: [{
					dic_value: '请选择施工类型',
				}, ],
				buildIndex: 0,
				buildUnit: '',
				buildPerson: '',

				// 新增需求
				tabsChanges: ['设备', '综合事务'],
				tabChangeCur: 0,
				searchKey1: '',
				deviceList: [],
				deviceInfo: {},
				device_id: '',
				partitionList: [],
				deptInfo:{}
			}
		},
		methods: {
			selectPartitionChange(e){
				 console.log(e,"e");
				 this.deptInfo = this.findDeviceById(this.partitionList,e[0])
				 console.log(this.deptInfo);
			},
			findDeviceById(deviceList, partition_id) {
			  for (let device of deviceList) {
			    if (device.partition_id == partition_id) {
			      return device;
			    }
			    if (device.children && device.children.length > 0) {
			      const found = this.findDeviceById(device.children, partition_id);
			      if (found) {
			        return found; 
			      }
			    }
			  }
			
			  return undefined;
			},
			//获取位置
			fetchPartition(name, type) {
				let params = {};
				if (type == 2) {
					params.partition_name = name;
				}
				uni.showLoading({
					title: "查询中...",
				});
				getBasePartitionList(params).then(res => {
					uni.hideLoading();
					this.partitionList = res.datas
					if (this.partitionList.length > 0) {
						this.$refs.partitionPicker._show();
					} else {
						uni.showToast({
							icon: "error",
							title: "未查询到相关位置信息",
							duration: 2000,
						});
					}

				})
			},
			removeDevice() {
				this.device_id = ''
				this.deviceInfo = {}
			},
			removeDeviceTwo(){
				this.deptInfo={}
			},
			resetClick() {
				this.$refs.device_popup.close()
			},
			confirmClick() {
				if (this.device_id) {
					this.deviceInfo = this.deviceList.find(v => v.device_id == this.device_id);
					this.$refs.device_popup.close()
					return
				}
				uni.showToast({
					icon: "error",
					title: "请选择数据",
					duration: 2000,
				});


			},
			onPopClickItem(index) {
				this.device_id = this.deviceList[index].device_id
				// for (let i = 0; i < this.deviceList.length; i++) {
				// 	this.$set(this.deviceList[i], 'selected', false)
				// }
				// this.$set(this.deviceList[index], 'selected', true)
			},
			tabSelect(e) {
				if (this.isComeFrom && this.inspectedType) {

				} else {
					this.tabChangeCur = e.currentTarget.dataset.id;
					console.log('TAB ', e)
				}

			},
			search1(res) {
				if (res.value) {
					this.searchKey1 = res.value;
					this.fetchDevice(this.searchKey1, 1)
				} else {
					uni.showToast({
						icon: "error",
						title: "请输入设备名称或设备位号",
						duration: 2000,
					});
				}

			},
			//获取设备
			fetchDevice(device, type) {
				let params = {
					device_name: device,
				};
				uni.showLoading({
					title: "查询中...",
				});
				getDeviceList(params).then(res => {
					uni.hideLoading();
					this.deviceList = res.datas;
					if (this.deviceList.length > 0) {
						this.deviceInfo = {}
						this.device_id = ''
						this.$refs.device_popup.open()
					} else {
						uni.showToast({
							icon: "error",
							title: "未查询到相关设备",
							duration: 2000,
						});
					}


				})
			},
			clear1(res) {
				this.searchKey1 = "";
				this.$refs.device_popup.close()
			},





			otypeChange: function(e) {
				this.otIndex = e.detail.value
			},
			billChange: function(e) {
				this.billIndex = e.detail.value
				let type = e.detail.value
				this.showBuild = false
				this.isBidding = false
				if (type == 1) {
					this.isBidding = true
				}
				if (type == 2) {
					//外协
					this.showBuild = true
				}
			},
			/* dateChange(e) {
				this.permissionDate = e
			}, */
			radioChange: function(evt) {
				if ('r1' === evt.detail.value) {
					this.result = true
				} else {
					this.result = false
				}
			},
			biddingChange(e) {
				this.isBidding = e.detail.value
			},
			// 查询班组
			fetchTeamData() {
				getTeamList().then((res) => {
					this.teams = this.teams.concat(res.datas)
				})
			},
			teamPickerChange(e) {
				this.teamIndex = e.detail.value
			},

			// 查询三级部门
			fetchDepts() {
				getThirdLevelDepts().then((res) => {
					for (let i = 0; i < res.datas.length; i++) {
						this.auditDepts.push(res.datas[i])
						if (res.datas[i].dept_id == this.deptId) {
							this.useIndex = i + 1
						}
						this.useDepts.push(res.datas[i])
					}
				})
			},
			auditDeptChange(e) {
				this.auditIndex = e.detail.value
			},
			useDeptChange(e) {
				this.useIndex = e.detail.value
			},

			// 查询装置
			fetchEqs() {
				getEqList().then((res) => {
					this.eqs = this.eqs.concat(res.datas)
				})
			},
			eqChange(e) {
				this.eqIndex = e.detail.value
			},

			//查询施工类型
			fetchBuildType() {
				getBuildType().then((res) => {
					this.build = this.build.concat(res.datas)
				})
			},
			buildChange(e) {
				this.buildIndex = e.detail.value
			},

			async startSign() {
				let s = await this.$refs.sig.getSyncSignature()
				console.log('签名数据0', s)
				svg2Png(s, (e) => {
					this.signPng = e
					console.log('签名数据1', this.signPng)
				})
			},
			picSelect(e) {
				console.log('SELECT', e.tempFilePaths)
				this.batchCompress(e.tempFilePaths)
				// this.uploadImg(e.tempFilePaths, 0)
			},
			picDelete(e) {
				console.log('DELETE', e)
				this.deletePic(e.tempFile.path)
			},
			previewImg(urls) {
				// for (let i = 0; i < urls.length; i ++) {
				// 	urls[i] = uploadImgUrl + urls[i]
				// }
				// uni.previewImage({
				// 	urls: urls
				// });
			},
			// 批量压缩
			batchCompress(paths) {
				console.log('paths', paths);
				this.$refs.helangCompress
					.batchCompress({
						batchSrc: paths,
						maxSize: 500,
						fileType: 'png',
						quality: 0.4,
						minSize: 180,
						progress: (res) => {
							uni.showLoading({
								title: `进度:${res.done + res.fail}/${res.count}`,
							})
							console.log(res)
						},
					})
					.then((res) => {
						uni.hideLoading()
						uni.showToast({
							title: '压缩完成',
							icon: 'success',
						})
						this.uploadImg(res, paths)
					})
					.catch((err) => {
						uni.hideLoading()
						uni.showToast({
							title: '压缩失败' + err,
							icon: 'none',
						})
					})
			},
			uploadImg(base64Pics, paths) {
				let imgs = []
				for (let i = 0; i < base64Pics.length; i++) {
					imgs.push({
						img: base64Pics[i].slice(22),
					})
				}
				let json = JSON.stringify(imgs)
				let params = {
					data: json,
				}
				uploadBase64Img(params).then((res) => {
					console.log('UPLOAD', res)
					let json = res.datas
					for (let j = 0; j < json.length; j++) {
						this.imgPaths.push({
							path: paths[j],
							pic_url: json[j].new_file_url,
						})
					}
				})
			},
			deletePic(path) {
				for (let i = 0; i < this.imgPaths.length; i++) {
					if (path == this.imgPaths[i].path) {
						this.imgPaths.splice(i, 1)
						console.log('PATH', this.imgPaths)
						return
					}
				}
			},

			submitData() {
				// this.tabChangeCur ==0?this.deviceInfo.device_id:this.deptInfo.partition_id || ''
				if( this.tabChangeCur ==0&& !this.deviceInfo.device_id ){
					uni.showToast({
						title: '请选择设备',
						icon: 'none',
					})
					return
				}
				if(this.tabChangeCur ==1  && !this.deptInfo.partition_id){
					uni.showToast({
						title: '请选择位置',
						icon: 'none',
					})
					return
				}
				if (this.buildIndex == 0) {
					uni.showToast({
						title: '请选择施工类型',
						icon: 'none',
					})
					return
				}
				if (this.showBuild) {
					if (this.buildUnit == '') {
						uni.showToast({
							title: '请填写施工单位',
							icon: 'none',
						})
						return
					}
					if (this.buildPerson == '') {
						uni.showToast({
							title: '请填写施工单位负责人',
							icon: 'none',
						})
						return
					}
				}
				// if (this.eqIndex == 0 &&this.tabChangeCur ==0 ) {
				// 	uni.showToast({
				// 		title: '请选择检修装置',
				// 		icon: 'none',
				// 	})
				// 	return
				// }
				// if (this.deviceName == '') {
				// 	uni.showToast({
				// 		title: '请填写设备名称',
				// 		icon: 'none',
				// 	})
				// 	return
				// }
				// if (this.deviceCode == '') {
				// 	uni.showToast({
				// 		title: '请填写设备位号',
				// 		icon: 'none',
				// 	})
				// 	return
				// }
				// if (this.workHours == '') {
				// 	uni.showToast({
				// 		title: '请填写工时',
				// 		icon: 'none',
				// 	})
				// 	return
				// }
				// if (this.imgPaths.length == 0) {
				// 	uni.showToast({
				// 		title: '请先拍照取证',
				// 		icon: 'none',
				// 	})
				// 	return
				// }
				if (this.content == '') {
					uni.showToast({
						title: '请填写检修内容',
						icon: 'none',
					})
					return
				}
				if (this.permissionDate == '') {
					uni.showToast({
						title: '请选择计划开始时间',
						icon: 'none',
					})
					return
				}
				if (this.permissionEndDate == '') {
					uni.showToast({
						title: '请选择计划结束时间',
						icon: 'none',
					})
					return
				}
				if (isCompareTime(this.permissionDate, this.permissionEndDate)) {
					uni.showToast({
						title: '结束时间不能小于开始时间',
						icon: 'none',
					})
					return
				}
				if (this.auditIndex == 0) {
					uni.showToast({
						title: '请选择审核部门',
						icon: 'none',
					})
					return
				}
				if (this.useIndex == 0) {
					uni.showToast({
						title: '请选择使用部门',
						icon: 'none',
					})
					return
				}
				if (this.type == 1) {
					if (this.signStr == '') {
						uni.showToast({
							title: '请签名确认',
							icon: 'none',
						})
						return
					}
					if (!this.isBidding) {
						if (this.teamIndex == 0) {
							uni.showToast({
								title: '请选择接收任务班组',
								icon: 'none',
							})
							return
						}
					}
				}
				
				if(this.tabChangeCur ==0){
					if(!this.deviceInfo.device_id){
						uni.showToast({
							title: '请选择设备',
							icon: 'none',
						})
					}
				}
				if(this.tabChangeCur ==1){
					if(!this.deptId.partition_id){
						uni.showToast({
							title: '请选择部门',
							icon: 'none',
						})
					}
				}
				let params
				let bidding = this.isBidding ? 1 : 0
				if (this.type == 0) {
					params = {
						equipment_name: this.eqs[this.eqIndex].dic_id || '',
						device_name: this.deviceName,
						is_bidding: bidding,
						permission_date: this.permissionDate,
						device_no: this.deviceCode,
						check_content: this.content,
						create_user: this.userId,
						audit_dept: this.auditDepts[this.auditIndex].dept_id,
						use_dept: this.useDepts[this.useIndex].dept_id,
						apply_dept: this.deptId,
						work_hours: this.workHours,
						status: 1,
						pic: this.imgPaths.length>0?JSON.stringify(this.imgPaths):'',
						overhaul_type: this.otIndex + 1,
						bill_type: this.billIndex + 1,
						build_type: this.build[this.buildIndex].dic_id,
						permission_end_date: this.permissionEndDate,
						build_unit: this.buildUnit,
						build_person: this.buildPerson,
						fault_class:this.tabChangeCur+1,
						device_id:this.tabChangeCur ==0?this.deviceInfo.device_id:this.deptInfo.partition_id || ''
					}
				} else if (this.type == 1) {
					if (this.isBidding) {
						params = {
							device_name: this.deviceName,
							is_bidding: bidding,
							device_no: this.deviceCode,
							check_content: this.content,
							create_user: this.userId,
							apply_dept: this.deptId,
							work_hours: this.workHours,
							status: 3,
							pic: JSON.stringify(this.imgPaths),
							audit_user: this.userId,
							audit_date: this.now,
							permission_date: this.permissionDate,
							audit_sign: this.signPng,
							fault_class:this.tabChangeCur+1,
							device_id:this.tabChangeCur ==0?this.deviceInfo.device_id:this.deptInfo.partition_id || ''
						}
					} else {
						params = {
							device_name: this.deviceName,
							is_bidding: bidding,
							team_id: this.teams[this.teamIndex].team_id,
							monitor_user: this.teams[this.teamIndex].monitor_user,
							device_no: this.deviceCode,
							check_content: this.content,
							create_user: this.userId,
							apply_dept: this.deptId,
							work_hours: this.workHours,
							status: 3,
							pic: JSON.stringify(this.imgPaths),
							audit_user: this.userId,
							audit_date: this.now,
							permission_date: this.permissionDate,
							audit_sign: this.signPng,
							fault_class:this.tabChangeCur+1,
							device_id:this.tabChangeCur ==0?this.deviceInfo.device_id:this.deptInfo.partition_id || ''
						}
					}
				}
				uni.showLoading({
					title: '正在提交',
				})
				console.log('params', params);
				saveOverhaulInfo(params).then((res) => {
					uni.showToast({
						title: '提交成功',
						icon: 'success',
						duration: 1500,
					})
					setTimeout(function() {
						window.android.finishWeb()
					}, 500)
				})
			},
		},
		onLoad: function(e) {
			this.type = e.type
			this.userName = e.userName
			this.userId = e.userId
			this.deptName = e.deptName
			this.deptId = e.deptId
			this.now = getFormatDateTime()
			this.fetchTeamData()
			this.fetchDepts()
			this.fetchEqs()
			this.fetchBuildType()
			setTimeout(() => {
				this.permissionDate = getFormatDateTime()
			}, 500)
		},
	}
</script>

<style>
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #fff;
	}

	view {
		font-size: 28upx;
		line-height: inherit;
	}

	.content {
		width: 100%;
		margin: 0 auto 80upx;
	}

	.example {
		width: 91%;
		margin: 20upx auto 20upx;
		padding: 0 30upx 0upx;
	}

	.example-body {
		padding: 0 40upx;
	}

	.buttn {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 5;
		padding: 20rpx;
		display: flex;
		justify-content: center;
		background-color: #FFF;
		
	}

	.buttn button {
		font-size: 30upx;
		background: #267dff;
		border-radius: 0;
		flex: 1;
		border-radius: 8rpx;
	}

	.criter_bt {
		padding: 0 10px;
		height: 50px;
		background-color: #f7f7f7;
		font-weight: normal;
		display: flex;
		align-items: center;
		flex-direction: row;
	}

	.line {
		width: 8upx;
		height: 30upx;
		background: #267dff;
		border-radius: 10upx;
		display: inline-block;
		vertical-align: middle;
	}

	.criter_bt text {
		padding-left: 10upx;
		vertical-align: middle;
		font-size: 32upx;
		color: #333333;
	}

	.dec_main {
		width: 94%;
	}

	.dec_li {
		width: 100%;
		margin: 30rpx 20rpx;
		overflow: hidden;
	}

	.dush_li {
		border-bottom: 1upx solid #f4f4f4;
		padding-bottom: 20upx;
	}

	.dec_le {
		width: 30%;
		float: left;
	}

	.dec_ri {
		float: left;
		width: 70%;
	}

	.dec_flex {
		height: 60upx;
		display: flex;
		align-items: center;
	}

	.dec_li label {
		color: #267dff;
		font-size: 30upx;
	}

	.dec_li text {
		color: #666666;
		font-size: 30upx;
	}

	.dec_li .inppu {
		font-size: 30upx;
	}

	.sign-view {
		display: flex;
		align-items: center;
	}

	.sign-view image {
		width: 150rpx;
		height: 60rpx;
		border: #d4ced8 solid 1rpx;
		border-radius: 5rpx;
		margin-right: 30rpx;
	}

	.sign-view text {
		width: 150rpx;
		height: 60rpx;
		border: #267dff solid 1rpx;
		border-radius: 5rpx;
		color: #267dff;
		font-size: 45rpx;
		text-align: center;
	}

	.signture {
		width: 0;
		height: 0;
	}

	.m-picker {
		margin-left: -25rpx;
	}

	.bottom-view {
		height: 100rpx;
		display: flex;
		align-items: center;
	}

	.sw-item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 20rpx;
		margin-top: -20rpx;
	}

	.sw-label {
		color: #267dff;
		font-size: 30upx;
	}

	.choose-box {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx;
		background: #fff;
		margin-bottom: 20rpx;
	}

	.bg-white {
		background-color: #ffffff;
		color: #666666;
	}

	.nav {
		white-space: nowrap;
	}

	.text-center {
		display: flex;
		align-items: center;
		padding: 0 30rpx;
		margin-top: 30rpx;
	}


	.cu-item {
		text-align: center;
		flex: 1;
		height: 82rpx;
		display: inline-block;
		line-height: 82rpx;
		margin: 0 10rpx;
		padding: 0 20px;
		border-radius: 41px;
		background-color: #e8f1ff;
		color: black;
	}

	.tab-date-on {
		background-color: #058cf5 !important;
		color: #e8f1ff !important;
	}

	.search {
		margin-top: 18rpx;
	}

	.popup-content {
		border-radius: 10rpx;
		background-color: #ffffff;
		width: 100%;
		padding: 20rpx 0;
		max-height: 1200rpx;
		overflow: auto;
	}

	.popup-title {
		color: #1b1b1b;
		font-size: 30rpx;
		margin-top: 20rpx;
		margin-bottom: 20rpx;
		font-weight: bold;
		text-align: center;
	}

	.card-action {
		display: flex;
		padding: 15rpx 30rpx;
		background-color: white;
		border-top: 1upx solid #eee;
		align-items: center;
		justify-content: center;
	}

	.card-content {
		display: flex;
		margin-top: 5rpx;

	}

	.card-desc {
		color: #999999;
		flex-shrink: 0;
		flex-wrap: nowrap;
		font-size: 28rpx;
		min-width: 150rpx;
	}

	.card-value {
		color: #000000;
		font-size: 28rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		// 只要超过宽度就换行，不论中文还是英文
		word-break: break-all;
		//最多展示两行
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
	}

	.con_btn {
		width: 100%;
		padding-bottom: 20rpx;
		z-index: 1;
		display: flex;
		bottom: 0;
		position: fixed;
		justify-content: space-between;
		background-color: white;
	}



	.confirm-btn {
		flex: auto;
		margin-left: 10rpx;
		margin-right: 10rpx;
	}

	.check-tag {
		font-size: 28rpx;
		width: 40rpx;
		height: 40rpx;
		position: absolute;
		right: 20rpx;
		top: 25rpx;
	}

	.deviceInfo {
		display: flex;
		padding: 40rpx;
		align-items: center;
		justify-content: space-between;

	}

	.deviceInfo_label {
		color: #999999;
		flex-shrink: 0;
		flex-wrap: nowrap;
		font-size: 28rpx;
		min-width: 156rpx;

	}

	.deviceInfo_val {
		color: #000000;
		font-size: 28rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		word-break: break-all;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
	}

	.label {
		margin-top: 8rpx;
	}
</style>